package hooks

import (
	"encoding/json"
	"time"
)

type Commit struct {
	Id        string    `json:"id"`
	TreeId    string    `json:"tree_id"`
	ParentIds []string  `json:"parent_ids"`
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
	Url       string    `json:"url"`
	Author    Author    `json:"author"`
	Committer struct {
		Name  string `json:"name"`
		Email string `json:"email"`
	} `json:"committer"`
	Distinct bool          `json:"distinct"`
	Added    []interface{} `json:"added"`
	Removed  []interface{} `json:"removed"`
	Modified []string      `json:"modified"`
}

// GiteePushHook WebHook push json to struct.
type GiteePushHook struct {
	Ref                string      `json:"ref"`
	Before             string      `json:"before"`
	After              string      `json:"after"`
	Created            bool        `json:"created"`
	Deleted            bool        `json:"deleted"`
	Compare            string      `json:"compare"`
	Commits            []Commit    `json:"commits"`
	HeadCommit         Commit      `json:"head_commit"`
	TotalCommitsCount  int         `json:"total_commits_count"`
	CommitsMoreThanTen bool        `json:"commits_more_than_ten"`
	Repository         Repo        `json:"repository"`
	Project            Repo        `json:"project"`
	UserId             int         `json:"user_id"`
	UserName           string      `json:"user_name"`
	User               BaseUser    `json:"user"`
	Pusher             BaseUser    `json:"pusher"`
	Sender             CommonUser  `json:"sender"`
	Enterprise         interface{} `json:"enterprise"`
	HookName           string      `json:"hook_name"`
	HookId             int         `json:"hook_id"`
	HookUrl            string      `json:"hook_url"`
	Password           string      `json:"password"`
	Timestamp          string      `json:"timestamp"`
	Sign               string      `json:"sign"`
}

func (g *GiteePushHook) UnMarshal(in []byte) error {
	return json.Unmarshal(in, g)
}
